<template>
  <div>
    <div class="container">
      <!-- Order Header -->
      <div class="order-header fade-in enhanced-card">
        <h1 class="order-title">Help {{ orderData?.list[0]?.uname }} Order Food</h1>
        <p class="order-subtitle">You're sending comfort food to your friend</p>
        <span class="recipient-badge">
          <i class="bi bi-person-heart"></i>
          Ordering for Sofia
        </span>
        <div class="status-badge" style="margin-top: 15px;">
          <i class="bi bi-check-circle-fill"></i>
          Prepared & Ready to Cook
        </div>
      </div>

      <!-- Countdown Timer -->
      <!-- <div class="countdown-container fade-in">
        <div class="countdown-title">
          <i class="bi bi-hourglass-split"></i> Limited Time Offer
        </div>
        <div class="progress-container">
          <div class="progress-bar" id="offerProgressBar"></div>
        </div>
        <div class="countdown-timer" id="countdownTimer">
          <div class="countdown-box">
            <div class="countdown-value" id="minutes">60</div>
            <div class="countdown-label">min</div>
          </div>
          <div class="countdown-box">
            <div class="countdown-value" id="seconds">00</div>
            <div class="countdown-label">sec</div>
          </div>

        </div>
        <div class="countdown-message">Complete your payment before this offer expires</div>
        <div class="urgency-badge">
          <i class="bi bi-lightning-fill"></i> Limited time only
        </div>
      </div> -->
      <!-- {{ orderData.countdown }} -->
      <CountdownTimer :totalSeconds="orderData.countdown" v-if="orderData.countdown" />

      <!-- Products Section -->
      <div class="products-section fade-in">
        <h2 class="section-title">Your Order</h2>

        <!-- Chicken Soup -->
        <div class="product-item enhanced-card" v-for="item in orderData.list">
          <img
            :src="item.goodsDataOne && item.goodsDataOne.head_img && item.goodsDataOne.head_img.length && item.goodsDataOne.head_img[0]"
            :alt="item.goods_name" class="product-image">

          <div class="product-details">
            <div>
              <div class="product-name">{{ item.goods_name }}</div>

              <div class="product-description">{{ item.remark }}</div>
            </div>
            <div class="product-price">${{ (item.order_money * item.order_number).toFixed(2) }}</div>
          </div>
        </div>
      </div>

      <!-- Delivery Info -->
      <div class="delivery-info fade-in enhanced-card"
        style="background: linear-gradient(135deg, #FFF5F5 0%, #FFEBEB 100%); border: 1px solid #FFDDDD;">
        <div class="delivery-time">
          <i class="bi bi-clock"></i>
          Estimated delivery: 35-45 minutes
        </div>
      </div>

      <!-- Address Info -->
      <div class="delivery-info fade-in enhanced-card"
        style="background: linear-gradient(135deg, #F0F8FF 0%, #E6F2FF 100%); border: 1px solid #D1E5FF; margin-top: -10px;">
        <div class="delivery-time" style="color: #0070ba;">
          <i class="bi bi-geo-alt"></i>
          {{ orderData.address }}
        </div>
      </div>

      <!-- Testimonial -->
     <!-- <div class="testimonial-card fade-in">
        <div class="testimonial-text">"Sofia absolutely loves their chicken soup when she's feeling under the weather.
          This will definitely cheer her up!"</div>
        <div class="testimonial-author">
          <i class="bi bi-person-circle"></i> From her friend, Emma
        </div>
      </div> -->

      <!-- Price Section -->
      <div class="price-section fade-in enhanced-card">
        <div class="price-row">
          <span class="price-label">Original Price</span>
          <span class="price-value">${{ orderData.original_price && orderData.original_price.toFixed(2) }}</span>
        </div>
        <div class="price-row">
          <span class="price-label">Coupon Money</span>
          <span class="price-value">${{ orderData.coupon_money && orderData.coupon_money.toFixed(2) }}</span>
        </div>
        <div class="price-row">
          <span class="price-label">Total Num</span>
          <span class="price-value">{{ orderData.total_num && orderData.total_num }} </span>
        </div>
        <div class="price-row total-row">
          <span class="total-label">Total</span>
          <span class="total-price">${{ orderData.total_money && orderData.total_money.toFixed(2) }}</span>
        </div>
      </div>

      <!-- Payment Section -->
      <div class="payment-section fade-in pulse enhanced-card">
        <h3 class="payment-title">Complete Your Order</h3>
        <div style="margin-bottom: 15px; text-align: center; font-size: 14px; color: var(--text-light);">
          <i class="bi bi-info-circle"></i> This payment secures Sofia's meal
        </div>

        <div class="paypal-button" @click="goToPay">
          <i class="bi bi-paypal"></i>
          Pay with PayPal
        </div>

        <div class="security-badges">
          <div class="security-badge">
            <i class="bi bi-shield-check"></i>
            <span>Secure Payment</span>
          </div>
          <div class="security-badge">
            <i class="bi bi-lightning-charge"></i>
            <span>Fast Processing</span>
          </div>
          <div class="security-badge">
            <i class="bi bi-truck"></i>
            <span>Live Tracking</span>
          </div>
        </div>
      </div>

      <!-- Additional Info -->
      <div class="fade-in" style="text-align: center; margin-bottom: 20px;">
        <div style="font-size: 14px; color: var(--text-light); margin-bottom: 5px;">
          <i class="bi bi-heart-fill" style="color: var(--primary-color);"></i>
          Sofia will receive a notification when you place this order
        </div>
        <div style="font-size: 13px; color: var(--text-muted);">
          Your generous gift will be delivered with care
        </div>
      </div>
    </div>
  </div>
</template>

<script lang='ts' setup>
import { ref } from 'vue'
import { ElMessage } from 'element-plus'
import { getUserOrderDataApi, payPalIndexApi } from '@/api/index'
import { useRoute } from 'vue-router'
import CountdownTimer from '@/components/CountdownTimer.vue'

const route = useRoute()

const orderNo = ref('')

orderNo.value = route.query.orderNo

const goToPay = async () => {
  try {
    const res = await payPalIndexApi({ order_no: orderNo.value})

    console.log(8978978989, res);

    if(res.code != 200) return ElMessage({
      type: 'error',
      message: res.msg
    })

    window.location.href = res.data.pay_url
  } catch (error) {
    ElMessage({
      type: 'error',
      message: error.msg
    })
  }
}

const orderData = ref({
  countdown: 0
})

const getUserOrderDataRequest = async () => {
  try {
    const res = await getUserOrderDataApi({
      orderNo: orderNo.value,
    })

    Object.assign(orderData.value, res.data)
  } catch (error) {
    ElMessage({
      type: 'error',
      message: error.msg
    })
  }
}

getUserOrderDataRequest()
</script>

<style>
:root {
  --primary-color: #EB1700;
  --secondary-color: #FF5733;
  --accent-color: #FFA500;
  --dark-color: #191919;
  --light-bg: #FFFFFF;
  --card-bg: #FFFFFF;
  --text-dark: #191919;
  --text-light: #5C5C5C;
  --text-muted: #767676;
  --success-color: #00AA5B;
  --border-color: #E8E8E8;
  --shadow-light: 0 2px 8px rgba(0, 0, 0, 0.08);
  --shadow-medium: 0 4px 16px rgba(0, 0, 0, 0.12);
  --shadow-heavy: 0 8px 32px rgba(0, 0, 0, 0.16);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background-color: #FAFAFA;
  color: var(--text-dark);
  line-height: 1.5;
  font-size: 16px;
}

.navbar {
  background: var(--light-bg);
  box-shadow: var(--shadow-light);
  padding: 16px 0;
  position: sticky;
  top: 0;
  z-index: 1000;
  border-bottom: 1px solid var(--border-color);
}

.navbar-brand {
  font-weight: 800;
  font-size: 28px;
  color: var(--primary-color) !important;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 12px;
  letter-spacing: -0.5px;
}

.brand-icon {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 20px;
  box-shadow: var(--shadow-light);
}

.container {
  max-width: 420px;
  margin: 0 auto;
  padding: 0 20px;
}

.order-header {
  background: var(--card-bg);
  border-radius: 16px;
  padding: 24px;
  margin: 20px 0;
  box-shadow: var(--shadow-light);
  text-align: center;
  border: 1px solid var(--border-color);
}

.order-title {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-dark);
  margin-bottom: 8px;
  letter-spacing: -0.3px;
}

.order-subtitle {
  color: var(--text-muted);
  font-size: 16px;
  margin-bottom: 20px;
  font-weight: 400;
}

.recipient-badge {
  background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
  color: white;
  padding: 10px 24px;
  border-radius: 24px;
  font-weight: 600;
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  box-shadow: var(--shadow-light);
}

.products-section {
  margin: 20px 0;
}

.section-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-dark);
  margin-bottom: 16px;
  letter-spacing: -0.2px;
}

.product-item {
  background: var(--card-bg);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: var(--shadow-light);
  margin-bottom: 16px;
  transition: all 0.3s ease;
  border: 1px solid var(--border-color);
  display: flex;
  gap: 16px;
  padding: 16px;
}

.product-item:hover {
  box-shadow: var(--shadow-medium);
}

.product-image {
  width: 80px;
  height: 80px;
  border-radius: 12px;
  object-fit: cover;
  flex-shrink: 0;
}

.product-details {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.product-name {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-dark);
  margin-bottom: 4px;
  letter-spacing: -0.1px;
}

.product-description {
  color: var(--text-light);
  font-size: 14px;
  line-height: 1.4;
  margin-bottom: 8px;
}

.product-price {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-dark);
  text-align: right;
}

.delivery-info {
  background: linear-gradient(135deg, #FFF5F5 0%, #FFEBEB 100%);
  border-radius: 12px;
  padding: 16px 20px;
  margin: 20px 0;
  text-align: center;
  border: 1px solid #FFDDDD;
}

.delivery-time {
  color: var(--primary-color);
  font-weight: 600;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.price-section {
  background: var(--card-bg);
  border-radius: 16px;
  padding: 24px;
  margin: 20px 0;
  box-shadow: var(--shadow-light);
  border: 1px solid var(--border-color);
}

.price-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.price-label {
  color: var(--text-light);
  font-size: 15px;
  font-weight: 500;
}

.price-value {
  font-weight: 600;
  color: var(--text-dark);
  font-size: 15px;
}

.total-row {
  border-top: 2px solid #F1F3F5;
  padding-top: 16px;
  margin-top: 16px;
}

.total-price {
  font-size: 22px;
  font-weight: 800;
  color: var(--text-dark);
}

.total-label {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-dark);
}

.payment-section {
  background: var(--card-bg);
  border-radius: 16px;
  padding: 24px;
  margin: 20px 0 32px 0;
  box-shadow: var(--shadow-medium);
  border: 1px solid var(--border-color);
}

.payment-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-dark);
  margin-bottom: 20px;
  text-align: center;
  letter-spacing: -0.2px;
}

.paypal-button {
  width: 100%;
  background: linear-gradient(135deg, #0070ba 0%, #005ea6 100%);
  color: white;
  border: none;
  border-radius: 12px;
  padding: 16px 24px;
  font-size: 16px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  cursor: pointer;
  transition: all 0.3s ease;
  text-decoration: none;
  box-shadow: var(--shadow-medium);
  letter-spacing: -0.1px;
}

.paypal-button:hover {
  background: linear-gradient(135deg, #005ea6 0%, #003d82 100%);
  transform: translateY(-2px);
  box-shadow: var(--shadow-heavy);
  color: white;
}

.paypal-button:active {
  transform: translateY(0);
}

.security-badges {
  display: flex;
  justify-content: center;
  gap: 24px;
  margin-top: 20px;
}

.security-badge {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
}

.security-badge i {
  font-size: 18px;
  color: var(--success-color);
}

.footer {
  text-align: center;
  padding: 24px 20px;
  color: var(--text-muted);
  font-size: 13px;
  background: var(--card-bg);
  margin-top: 20px;
  border-top: 1px solid var(--border-color);
}

.footer p {
  margin-bottom: 8px;
}

/* Animation classes */
.fade-in {
  animation: fadeIn 0.8s ease-out;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(24px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.pulse {
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% {
    transform: scale(1);
  }

  50% {
    transform: scale(1.01);
  }

  100% {
    transform: scale(1);
  }
}

/* Countdown Timer Styles */
.countdown-container {
  background: linear-gradient(135deg, #FFE8E0 0%, #FFF1EE 100%);
  border-radius: 16px;
  padding: 20px;
  margin: 20px 0 -10px 0;
  border: 2px dashed #FF8E73;
  position: relative;
  text-align: center;
  overflow: hidden;
}

.countdown-container::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: url("data:image/svg+xml,%3Csvg width='100' height='100' viewBox='0 0 100 100' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M11 18c3.866 0 7-3.134 7-7s-3.134-7-7-7-7 3.134-7 7 3.134 7 7 7zm48 25c3.866 0 7-3.134 7-7s-3.134-7-7-7-7 3.134-7 7 3.134 7 7 7zm-43-7c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zm63 31c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zM34 90c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zm56-76c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zM12 86c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm28-65c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm23-11c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zm-6 60c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm29 22c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zM32 63c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zm57-13c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zm-9-21c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2zM60 91c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2zM35 41c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2zM12 60c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2z' fill='%23FF8E73' fill-opacity='0.1' fill-rule='evenodd'/%3E%3C/svg%3E"),
    linear-gradient(135deg, #FFE8E0 0%, #FFF1EE 100%);
  z-index: 0;
  opacity: 0.5;
}

.countdown-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--primary-color);
  margin-bottom: 10px;
  position: relative;
  z-index: 1;
}

.countdown-timer {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 10px;
  position: relative;
  z-index: 1;
}

.countdown-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 60px;
}

.countdown-value {
  background: white;
  color: var(--primary-color);
  font-size: 20px;
  font-weight: 800;
  border-radius: 8px;
  width: 50px;
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-light);
  position: relative;
  overflow: hidden;
}

.countdown-value::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: rgba(0, 0, 0, 0.1);
  z-index: 1;
}

.countdown-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-top: 5px;
  text-transform: uppercase;
}

.countdown-message {
  font-size: 14px;
  color: var(--text-light);
  margin-top: 10px;
  position: relative;
  z-index: 1;
}

.urgency-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(235, 23, 0, 0.1);
  color: var(--primary-color);
  padding: 6px 12px;
  border-radius: 100px;
  font-size: 13px;
  font-weight: 600;
  margin-top: 12px;
  animation: pulse 2s infinite;
}

/* Enhanced Card Styles */
.enhanced-card {
  background: var(--card-bg);
  border-radius: 16px;
  box-shadow: var(--shadow-medium);
  transition: all 0.3s ease;
  border: 1px solid var(--border-color);
  position: relative;
  overflow: hidden;
}

.enhanced-card:hover {
  transform: translateY(-5px);
  box-shadow: var(--shadow-heavy);
}

.enhanced-card::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 5px;
  background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
}

/* Progress Bar Animation */
.progress-container {
  width: 100%;
  height: 8px;
  background: #f0f0f0;
  border-radius: 4px;
  overflow: hidden;
  margin: 10px 0;
}

.progress-bar {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
  animation: progressAnimation 60s linear forwards;
}

@keyframes progressAnimation {
  0% {
    width: 100%;
  }

  100% {
    width: 0%;
  }
}

/* Enhanced User Experience */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: #E6F7ED;
  color: var(--success-color);
  padding: 5px 10px;
  border-radius: 100px;
  font-size: 12px;
  font-weight: 600;
}

.testimonial-card {
  padding: 15px;
  background: #F9F9F9;
  border-radius: 12px;
  margin: 15px 0;
  border-left: 3px solid var(--accent-color);
}

.testimonial-text {
  font-size: 14px;
  font-style: italic;
  color: var(--text-light);
  margin-bottom: 10px;
}

.testimonial-author {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dark);
  display: flex;
  align-items: center;
  gap: 5px;
}

/* Responsive improvements */
@media (max-width: 375px) {
  .container {
    padding: 0 16px;
  }

  .order-header,
  .price-section,
  .payment-section {
    padding: 20px;
  }

  .navbar-brand {
    font-size: 24px;
  }

  .product-item {
    padding: 12px;
    gap: 12px;
  }

  .product-image {
    width: 70px;
    height: 70px;
  }
}
</style>
